#include "irrlicht.h"
#include <sys/time.h>
#include <iostream>

const long limit = 1000000;

void function1() 
{
  irr::core::vector3df a(1.0, 1.0, 1.0);
  irr::core::vector3df b(10.0, 10.0, 10.0);  
  irr::core::vector3df d(0.0, 0.0, 0.0);  

  for(long l = 0; l < limit - 1; l++)
    {
      d = a + b;
    }
  
}


void function2() 
{
  irr::core::vector3df a(1.0, 1.0, 1.0);
  irr::core::vector3df b(10.0, 10.0, 10.0);
  irr::core::vector3df d(0.0, 0.0, 0.0);
  for(long l = 0; l < limit - 1; l++ )
    {
      d = 3 * a + 4 * b;
    }
}



void function3() 
{
  irr::core::vector3df a(1.0, 1.0, 1.0);
  irr::core::vector3df b(10.0, 10.0, 10.0);
  irr::core::vector3df c(100.0, 100.0, 100.0);
  irr::core::vector3df d(0.0, 0.0, 0.0);  
  for( long l = 0; l < limit - 1; l++ )
    {
      d = a + 3 * (b + c);
    }
}

void function4() 
{
  irr::core::vector3df a(1.0, 1.0, 1.0);
  irr::core::vector3df b(10.0, 10.0, 10.0);
  irr::core::vector3df c(100.0, 100.0, 100.0);
  irr::core::vector3df d(0.0, 0.0, 0.0);  
  for( long l = 0; l < limit - 1; l++ )
    {
      d = 3 * a + 4 * b + 5 * c;
    }
}


int main() 
{
  int timerMode = ITIMER_VIRTUAL;
  struct itimerval endCount;
  struct itimerval startCount;
  long timedif = 0;
  endCount.it_interval.tv_sec = 0;
  endCount.it_interval.tv_usec = 0;
  endCount.it_value.tv_sec = 1000000;
  endCount.it_value.tv_usec = 0;
  

   
  setitimer(timerMode, &endCount, NULL);
  getitimer(timerMode, &startCount);
  function1();
  getitimer(timerMode, &endCount);
  timedif = 1000000 * (startCount.it_value.tv_sec - endCount.it_value.tv_sec) 
    + (startCount.it_value.tv_usec - endCount.it_value.tv_usec);
  std::cout << timedif << std::endl;
 

  
  setitimer(timerMode, &endCount, NULL);
  getitimer(timerMode, &startCount);
  function2();
  getitimer(timerMode, &endCount);
  timedif = 1000000 * (startCount.it_value.tv_sec - endCount.it_value.tv_sec) 
    + (startCount.it_value.tv_usec - endCount.it_value.tv_usec);
  std::cout << timedif << std::endl;
 
 
   setitimer(timerMode, &endCount, NULL);
  getitimer(timerMode, &startCount);
  function3();
  getitimer(timerMode, &endCount);
  timedif = 1000000 * (startCount.it_value.tv_sec - endCount.it_value.tv_sec) 
    + (startCount.it_value.tv_usec - endCount.it_value.tv_usec);
  std::cout << timedif << std::endl;
  

  
  setitimer(timerMode, &endCount, NULL);
  getitimer(timerMode, &startCount);
  function4();
  getitimer(timerMode, &endCount);
  timedif = 1000000 * (startCount.it_value.tv_sec - endCount.it_value.tv_sec) 
    + (startCount.it_value.tv_usec - endCount.it_value.tv_usec);
  std::cout << timedif << std::endl;
  
 
  return 0;
}
